import IShape from "../interfaces/IShape";
import ISprite from "../interfaces/ISprite";
import Sprite2D from "../spriteSystem/Sprite2D";
import Grid from "../shapes/Grid";
import Circle from "../shapes/Circle";
import Rect from "../shapes/Rect";
import Ellipse from "../shapes/Ellipse";
import Vector2 from "../maths/Vector2";
import ConvexPolygon from "../shapes/ConvexPolygon";
import Scale9Data from "../core/Scale9Data";
import Scale9Grid from "../core/Scale9Grid";
import Line from "../shapes/Line";
import Bone from "../shapes/Bone";
import BezierPath from "../shapes/BezierPath";

export default class SpriteFactory {
    public static createSprite(shape: IShape, name: string = ''): ISprite {
        let spr: ISprite = new Sprite2D(shape, name);
        return spr;
    }

    public static createGrid(w: number, h: number, xStep: number = 10, yStep: number = 10): IShape {
        return new Grid(w, h, xStep, yStep);
    }

    public static createCircle(radius: number): IShape {
        return new Circle(radius);
    }

    public static createRect(w: number, h: number, u: number = 0, v: number = 0): IShape {
        return new Rect(w, h, u, v);
    }

    public static createEllipse(radiusX: number, radiusY: number): IShape {
        return new Ellipse(radiusX, radiusY);
    }

    public static createPolygon(points: Vector2[]): IShape {
        if (points.length < 3) {
            throw new Error("多边形顶点数量必须大于或等于3!!!");
        }
        return new ConvexPolygon(points);
    }

    public static createScale9Grid(data: Scale9Data, width: number, height: number, u: number = 0, v: number = 0): IShape {
        return new Scale9Grid(data, width, height, u, v);
    }

    public static createLine(start: Vector2, end: Vector2): IShape {
        let line: Line = new Line();
        line.start = start;
        line.end = end;
        return line;
    }

    public static createXLine(len: number = 10, t: number = 0): IShape {
        return new Line(len, t);
    }

    public static createBone(len: number = 10, t: number = 0): IShape {
        return new Bone(len, t);
    }

    public static createISprite(shape: IShape, x: number = 0, y: number = 0, rotation: number = 0, scaleX: number = 1.0, scaleY: number = 1.0, name: string = ' '): ISprite {
        let spr: ISprite = new Sprite2D(shape, name);
        spr.x = x;
        spr.y = y;
        spr.rotation = rotation;
        spr.scaleX = scaleX;
        spr.scaleY = scaleY;
        return spr;
    }
    public static createBezierPath(points: Vector2[], isCubic: boolean = false): IShape {
        return new BezierPath(points, isCubic);
    }
}